import time
import subprocess
import os
#
# def log(command):
#     pro = subprocess.Popen(command, shell=True)
#     time.sleep(2)
#     pro.kill()
#
#     command = "adb logcat -v time > Y:\log.log"
#     log(command)
# cmd = ["adb", "logcat", "-v", "time", "*:E"]
cmd1 = ["adb", "logcat", "-v", "time"]
# pro = subprocess.Popen(cmd, stdout=subprocess.PIPE)
pro1 = subprocess.Popen(cmd1, stdout=subprocess.PIPE)
x=0
y=0
z=0
o=0
while True:
    with open('log.txt', 'a') as file:

        lines = str(pro1.stdout.readline().strip().decode("utf-8", errors="ignore"))
        if 'E/' in lines:
            print(lines)
        x += lines.count('D/')
        y += lines.count('W/')
        z += lines.count('I/')
        o += lines.count('E/')
        file.write(lines + '\n')
        # print(lines.find('E/'))
        print('--------------\n'
              '调试：%s\n'
              '错误：%s\n'
              '消息：%s\n'
              '警告：%s\n'
              '--------------'
              % (x, o, z, y))
    # line = pro.stdout.readline()
    # if not line:
    #     break
    # print(line.strip().decode("utf-8", errors="ignore"))
    time.sleep(2)
